package com.loveyukari.utils;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AliDayuUtils {

    private static Logger log = LoggerFactory.getLogger(AliDayuUtils.class);

    private static String APP_KEY = "23556355";
    private static String APP_SECRET = "8abcb0f504db1b5cf87e256e824a35db";
    private static String SEND_URL = "http://gw.api.taobao.com/router/rest";
    private static String SEND_LIUYAN_NUM ="SMS_44500115";
    private static String SEND_PHONE_LIVE_ALERT = "SMS_107100202";

    public static void sendPhoneLiveAlert(String phone,String name){
        TaobaoClient client = new DefaultTaobaoClient(SEND_URL, APP_KEY, APP_SECRET);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setSmsType("normal");
        req.setSmsFreeSignName("小缘");
        req.setSmsParamString("{\"name\":\""+name+"\"}");
        req.setRecNum(phone);
        req.setSmsTemplateCode(SEND_PHONE_LIVE_ALERT);
        try {
            log.info("send me name: "+name);
            AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
            log.info(rsp.getBody());
        } catch (ApiException e) {
            log.error(e.getMessage(),e);
        }
    }

    public static void sendMeLiuyan(String txt){
        TaobaoClient client = new DefaultTaobaoClient(SEND_URL, APP_KEY, APP_SECRET);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setSmsType("normal");
        req.setSmsFreeSignName("小缘");
        req.setSmsParamString("{\"txt\":\""+txt+"\"}");
        req.setRecNum("18868877652");
        req.setSmsTemplateCode(SEND_LIUYAN_NUM);
        try {
            log.info("send me txt: "+txt);
            AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
            log.info(rsp.getBody());
        } catch (ApiException e) {
            log.error(e.getMessage(),e);
        }
    }

}
